import { useEffect } from 'react';
import { useFrame } from '@react-three/fiber';
import { useThree } from '@react-three/fiber';
import { danmuOcclusionService } from '../services/danmuOcclusionService';
import * as THREE from 'three';

interface UseCharacterPositionUpdaterProps {
    characterPosition: THREE.Vector3;
    enabled: boolean;
}

export const useCharacterPositionUpdater = ({
    characterPosition,
    enabled
}: UseCharacterPositionUpdaterProps) => {
    const { camera, size } = useThree();

    useFrame(() => {
        if (enabled && characterPosition && danmuOcclusionService) {
            try {
                danmuOcclusionService.updateCharacterScreenPosition(
                    characterPosition,
                    camera,
                    size.width,
                    size.height
                );
            } catch (error) {
                console.warn('人物位置更新失败:', error);
            }
        }
    });
};
